﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  UcmaPresenceProviderTest.cs
//    
// Abstract:
//
//  Unit tests for UcmaPresenceProvider
//  
//--

using Microsoft.Rtc.Collaboration.Presence;
using Microsoft.Rtc.Internal.Collaboration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.EnhancedReminders.Dispatcher.UnitTests
{
        
    /// <summary>
    ///This is a test class for UcmaPresenceProviderTest and is intended
    ///to contain all UcmaPresenceProviderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UcmaPresenceProviderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        /// A test for ConvertPresenceStateToPresenceStates. Confirm that we return a user's presence
        /// as "away" when they have an unknown activity token.
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Microsoft.EnhancedReminders.DispatcherService.exe")]
        public void TestActivityTokenOnNonBusy()
        {
            PresenceAvailability availability = PresenceAvailability.Away; 
            PresenceActivity activity = new PresenceActivity("on-the-phone"); 

            PresenceStates expected = PresenceStates.Away;
            PresenceStates actual = UcmaPresenceProvider_Accessor.ConvertPresenceStateToPresenceStates(availability, activity);

            Assert.AreEqual(expected, actual, "Presence should be unknown, was " + actual);
        }

        /// <summary>
        ///A test for ConvertPresenceStateToPresenceStates
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Microsoft.EnhancedReminders.DispatcherService.exe")]
        public void TestValidAvailable()
        {
            PresenceAvailability availability = PresenceAvailability.Online;
            PresenceActivity activity = null;

            PresenceStates expected = PresenceStates.Available;
            PresenceStates actual = UcmaPresenceProvider_Accessor.ConvertPresenceStateToPresenceStates(availability, activity);

            Assert.AreEqual(expected, actual, "Presence should be available, was " + actual);
        }

        /// <summary>
        ///A test for ConvertPresenceStateToPresenceStates
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Microsoft.EnhancedReminders.DispatcherService.exe")]
        public void TestBusyWithActivity()
        {
            PresenceAvailability availability = PresenceAvailability.Busy;
            PresenceActivity activity = new PresenceActivity("on-the-phone");

            PresenceStates expected = PresenceStates.InACall;
            PresenceStates actual = UcmaPresenceProvider_Accessor.ConvertPresenceStateToPresenceStates(availability, activity);

            Assert.AreEqual(expected, actual, "Presence should be In A Call, was " + actual);
        }

        /// <summary>
        ///A test for ConvertPresenceStateToPresenceStates
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Microsoft.EnhancedReminders.DispatcherService.exe")]
        public void TestBusyWithoutActivity()
        {
            PresenceAvailability availability = PresenceAvailability.Busy;
            PresenceActivity activity = null;

            PresenceStates expected = PresenceStates.Busy;
            PresenceStates actual = UcmaPresenceProvider_Accessor.ConvertPresenceStateToPresenceStates(availability, activity);

            Assert.AreEqual(expected, actual, "Presence should be Busy, was " + actual);
        }

        /// <summary>
        /// A test for ConvertPresenceStateToPresenceStates: confirm that we parse a
        /// user's presence as 'busy' when they have an unrecognized ActivityToken.
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Microsoft.EnhancedReminders.DispatcherService.exe")]
        public void TestBusyWithUnknownActivity()
        {
            PresenceAvailability availability = PresenceAvailability.Busy;
            PresenceActivity activity = new PresenceActivity("not-real");

            PresenceStates expected = PresenceStates.Busy;
            PresenceStates actual = UcmaPresenceProvider_Accessor.ConvertPresenceStateToPresenceStates(availability, activity);

            Assert.AreEqual(expected, actual, "Presence should be unknown, was " + actual);
        }
    }
}
